package com.dao.front.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.dao.BaseDao;
import com.dao.front.IQuserFrontDAO;
import com.entity.Quser;

@Repository
public class QuserDAOFrontImpl extends BaseDao implements IQuserFrontDAO{

	@Override
	public List<Map<String, Object>> findAll() {
		String sql="select qId,qAccount,qPwd,qVip from quser";
		return executeQuery(sql, null);
	}

	@Override
	public int doAll(Quser quser) {
		String sql="insert into quser"
				+ " (qAccount,qPwd,qVip)"
				+ " values"
				+ " (?,?,?)";
		Object[] params={quser.getqAccount(),quser.getqPwd(),quser.getqVip()};
		return executeUpdate(sql, params);
	}

	@Override
	public Quser isByQuser(String qAccount, String qPwd) {
		String sql="select qId,qAccount,qPwd,qVip"
				+ " from quser"
				+ " where qAccount=? and qPwd=?";
		Object[] params={qAccount,qPwd};
		List<Map<String,Object>> list=executeQuery(sql, params);
		if(list.size()>0){
			Quser quser=new Quser();
			Map<String, Object> map=list.get(0);
			quser.setqId((Integer)map.get("qId"));
			quser.setqAccount((String)map.get("qAccount"));
			quser.setqPwd((String)map.get("qPwd"));
			return quser;
		}
		return null;
	}

	@Override
	public Quser isByAccount(String qAccount) {
		String sql="select qId,qAccount,qPwd,qVip"
				+ " from quser"
				+ " where qAccount=?";
		Object[] params={qAccount};
		List<Map<String,Object>> count=executeQuery(sql, params);
		if(count.size()>0){
			Quser quser=new Quser();
			quser.setqAccount(qAccount);
			return quser;
		}
		return null;
	}


}
